﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TasksModel;
using System.Diagnostics;

namespace TasksUnitTests
{
    public class BasicTests
    {
        public class IOTest : IdentifiedObject
        {
            public void TestCutMilliseconds()
            {
                DateTime dt = IdentifiedObject.CutMilliseconds(new DateTime(2001, 01, 01, 01, 01, 01, 999, DateTimeKind.Utc));
                Debug.Assert(dt.Millisecond == 0);
            }
        }

        public static void tz()
        {
            TimeZoneInfo cet = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
            DateTimeTz tz = new DateTimeTz(new DateTime(2000, 01, 01, 0, 0, 0), cet);
            Debug.Assert(tz.LocalDateTime == new DateTime(2000, 01, 01, 1, 0, 0));

            DateTime d = DateTimeTz.ToLocal(new DateTime(2000, 01, 01, 0, 0, 0), cet);
            Debug.Assert(d == new DateTime(2000, 01, 01, 1, 0, 0));
            d = DateTimeTz.ToUTC(d, cet);
            Debug.Assert(d == new DateTime(2000, 01, 01, 0, 0, 0));

            Task t = new Task();
            t.TimeZone = cet.Id;
            t.CreatedAt = new DateTime(2000, 01, 01, 0, 0, 0, DateTimeKind.Utc);
            Debug.Assert(t.LocalCreatedAt == new DateTime(2000, 01, 01, 1, 0, 0));
        }

        public static void Xml()
        {
            Task t = new Task();
            string xml = new TaskSerializer<Task>().Serialize(t);

            Task t1 = new TaskSerializer<Task>().Deserialize(xml);

            Debug.Assert(t1.ID == t.ID);
        }

        public static void Run()
        {
            tz();

            Xml();

            new IOTest().TestCutMilliseconds();
        }
    }
}
